﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Library;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Model;

namespace IHISCETeim.Web.MachineSys.YYModel
{
    public partial class YYShipmentListEasyUI : EasyUIPageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看, Permission.修改, Permission.新增, Permission.删除 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "YYShipmentListEasyUI";
            }
        }

        #region 属性 (查询条件)

         [QueryColumnName(), QueryOperator(QueryOperatorsEnum.包含)]
        public string AgentName
        {
            get
            {
                return GetRequestValue<string>("AgentName", "");

            }
        }
         [QueryColumnName(), QueryOperator(QueryOperatorsEnum.包含)]
         public string Status
        {
            get
            {
                string s = GetRequestValue<string>("Status", "未发");
                if (s == "所有")
                    return "";
                return s;
            }
        }
         [QueryColumnName("ExpectOutDate"), QueryOperator(QueryOperatorsEnum.大于等于)]
         public string ExpectOutDateFrom
        {
            get
            {
                return GetRequestValue<string>("ExpectOutDateFrom", "");

            }
        }
         [QueryColumnName("ExpectOutDate"), QueryOperator(QueryOperatorsEnum.小于等于)]
         public string ExpectOutDateTo
        {
            get
            {
                if (string.IsNullOrEmpty(ExpectOutDateFrom))
                {
                    return "";
                }
                else
                {
                    string todate = GetRequestValue<string>("ExpectOutDateTo", "");
                    if (string.IsNullOrEmpty(todate))
                        return Convert.ToDateTime(ExpectOutDateFrom).AddDays(1).ToShortDateString();
                    else
                        return todate;
                }

            }
        }

        [QueryColumnName("OutDate"), QueryOperator(QueryOperatorsEnum.大于等于)]
        public string OutDateFrom
        {
            get
            {
                return GetRequestValue<string>("OutDateFrom", "");

            }
        }
        [QueryColumnName("OutDate"), QueryOperator(QueryOperatorsEnum.小于等于)]
        public string OutDateTo
        {
            get
            {
                if (string.IsNullOrEmpty(OutDateFrom))
                {
                    return "";
                }
                else
                {
                    string todate = GetRequestValue<string>("OutDateTo", "");
                    if (string.IsNullOrEmpty(todate))
                        return Convert.ToDateTime(ExpectOutDateFrom).AddDays(1).ToShortDateString();
                    else
                        return todate;
                }

            }
        }


        [QueryColumnName(), QueryOperator(QueryOperatorsEnum.包含)]
         public string MacType
        {
            get
            {
                return GetRequestValue<string>("MacType", "");

            }
        }
         [QueryColumnName(), QueryOperator(QueryOperatorsEnum.包含)]
         public string SerialNumber
        {
            get
            {
                return GetRequestValue<string>("SerialNumber", "");

            }
        }
        #endregion

        /// <summary>
        /// 排序字段 值为 id
        /// </summary>
        protected override string orderField
        {
            get
            {
                return string.IsNullOrEmpty(base.orderField) ? "ShipmentID" : base.orderField;
            }
        }
        /// <summary>
        ///  排序方式 desc或 asc
        /// </summary>
        protected override string orderDirection
        {
            get
            {
                return string.IsNullOrEmpty(base.orderDirection) ? "DESC" : base.orderDirection;
            }
        }


        protected override string SQLSort
        {
            get
            {
                return (orderField + " " + orderDirection);
            }
        }

        protected string GetSQLWhere()
        {
            string wheresql = "";
            string sqlcommonFiled = "";
            if (!string.IsNullOrEmpty(AgentName))
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("AgentName", QueryOperatorsEnum.包含, AgentName);
                wheresql = sqlcommonFiled;
            }


            if (!string.IsNullOrEmpty(Status))
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("Status", QueryOperatorsEnum.等于, Status);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlcommonFiled;
                }
                else
                {
                    wheresql = sqlcommonFiled;
                }
            }

            if (!string.IsNullOrEmpty(ExpectOutDateFrom))
            {
                string DOWNSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("ExpectOutDate", QueryOperatorsEnum.范围, ExpectOutDateFrom + "|" + ExpectOutDateTo);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + DOWNSQL;
                }
                else
                {
                    wheresql = DOWNSQL;
                }
            }


            return wheresql;
        }

        protected override string query()
        {
            DataTable dts = null;

            dts = YYShipmentController.GetPagination(QueryFiledHelper.GetSqlWhere(this), pageNum, numPerPage, SQLSort, ref TotalCount);
            return ToDataGridJson(dts, TotalCount, null).ToString();
            // return ToDataGridJson(dts[0], TotalCount, dts[1]).ToString();
        }

        protected override string editrow()
        {
            int ShipmentID = GetRequestValue<int>("ShipmentID", 0);
            YYShipmentInfo obj = YYShipmentController.GetByID(ShipmentID);
            obj.Status = GetRequestValue<string>("Status", "Status");
            return  YYShipmentController.Update(obj)?"":"更新失败";
        }
    }
}